﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LINQ_Students
{
    class LINQtest
    {
        static void Main(string[] args)
        {
            var students = new[] {
                                    new {FirstName = "Nikolai", LastName = "Ivanov", Age = 30}, 
                                    new {FirstName = "Dimitar", LastName = "Petrov", Age = 20}, 
                                    new {FirstName = "Strahil", LastName = "Voivodov", Age = 24},
                                    new {FirstName = "Mile", LastName = "Kitic", Age = 21}, 
                                    new {FirstName = "Dragana", LastName = "Mirkovic", Age = 50}, 
                                    new {FirstName = "Stefan", LastName = "Georgiev", Age = 140},
                                    new {FirstName = "Nikolai", LastName = "Rusev", Age = 21}, 
                                    new {FirstName = "Maria", LastName = "Tosheva", Age = 31}, 
            };

            var studentList =
                from student in students
                where student.FirstName.CompareTo(student.LastName) < 0
                select student;

            foreach (var stud in studentList)
            {
                Console.WriteLine("{0} {1}", stud.FirstName, stud.LastName);
            }

            studentList =
                from student in students
                where student.Age >= 18 && student.Age <= 24
                select student;

            Console.WriteLine();
            foreach (var stud in studentList)
            {
                Console.WriteLine("{0} {1} {2}", stud.FirstName, stud.LastName, stud.Age);
            }

            var orderedStudents = students.OrderByDescending(st => st.FirstName).ThenByDescending(st => st.LastName);

            Console.WriteLine();
            foreach (var stud in orderedStudents)
            {
                Console.WriteLine("{0} {1} {2}", stud.FirstName, stud.LastName, stud.Age);
            }
        }
    }
}
